package com.LeeCode;

import java.util.Arrays;

/**
 * 将字符串拆分为若干长度为 k 的组
 */

public class Code2138 {
    public static void main(String[] args) {
        String s = "abcdefghi";
        int k = 3;
        char fill = 'x';
        System.out.println(Arrays.toString(new Code2138().divideString(s, k, fill)));
    }

    public String[] divideString(String s, int k, char fill) {
        StringBuilder sb = new StringBuilder(s);

        int total = s.length() / k, newTotal = (s.length() + k - 1) / k;
        for (int i = s.length(); i < newTotal * k; i++) {
            sb.append(fill);
        }

        String[] ans = new String[newTotal];
        for (int i = 0; i < sb.length(); i += k) {
            ans[i / k] = sb.substring(i, i + k);
        }
        return ans;
    }
}
